package solved;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/*
 ID:	liluyan1
 LANG:	JAVA
 TASK:	transform
 */
public class transform {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new FileReader("transform.in"));
		int min = new transform().minRotate(f);
		
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"transform.out")));
		out.println(min);
		out.close();
		System.exit(0);
	}
	
	private int minRotate(BufferedReader f) throws IOException {
		int N = Integer.parseInt(f.readLine());
		String[] before = readLines(N, f);
		String[] after = readLines(N, f);
		int min = 7;
		if (equals(before, after)) min = 6;
		if (equals(reflect(before), after)) min = 4;
		
		for (int i=0; i<3; i++) {
			String[] t = rotate(before);
			if (equals(t, after)) min = Math.min(min, i+1);
			before = t;
			if (equals(reflect(before), after)) min = Math.min(min, 5);
		}
		
		return min;
	}
	
	private String[] readLines(int N, BufferedReader f) throws IOException {
		String[] in = new String[N];
		for (int i=0; i<N; i++) {
			in[i] = f.readLine();
		}
		return in;
	}
	
	private String[] rotate(String[] s) {
		int N = s.length;
		String[] t = new String[N];
		for (int i=0; i<N; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j<N; j++) {
				sb.append(s[N-j-1].charAt(i));
			}
			t[i] = sb.toString();
		}
		return t;
	}
	
	private String[] reflect(String[] s) {
		int N = s.length;
		String[] t = new String[N];
		for (int i=0; i<N; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j=0; j<N; j++) {
				sb.append(s[i].charAt(N-j-1));
			}
			t[i] = sb.toString();
		}
		return t;
	}
	
	private boolean equals(String[] t, String[] after) {
		for (int i=0; i<t.length; i++) {
			if (!t[i].equals(after[i])) return false;
		}
		return true;
	}
}
